<?php

namespace App\Admin\Controllers;

use App\Models\VoteCls;
use Dcat\Admin\Form;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Tree;
use Illuminate\Support\Str;

class VoteClsController extends AdminController
{

    public function index(Content $content)
    {
        return $content->header('帖子分类管理')
            ->body(function(Row $row) {

                $tree = new Tree(new VoteCls);

                $tree->branch(function($branch) {
                    return "{$branch['id']} - {$branch['title']} - 排序：{$branch['sort_id']}";
                });

                $row->column(12,$tree);

            });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new VoteCls(),function(Form $form) {

            $form->disableResetButton();

            $form->disableEditingCheck();

            $form->disableViewCheck();

            $form->hidden('c_key');

            $form->select('parent_id')->options(VoteCls::selectOptions())->required()->default(0);

            $form->text('title');

            $form->number('sort_id')
                ->default(1)
                ->type('number')
                ->attribute('min',1)
                ->attribute('max',60);

            $form->editor('content')->height(800);

            $form->radio('is_using')->options([1 => '开启',0 => '禁用'])->default(1)->required('min:1');

            // 保存时
            $form->saving(function(Form $form) {
                $form->c_key = Str::uuid();
            });
        });
    }
}
